package com.zhentao.controller;


import com.zhentao.file.service.impl.FileStorageServiceImpl;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.common.enums.AppHttpCodeEnum;
import io.minio.errors.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;


@RestController
@RequestMapping("file")
@Api(tags = "FileUploadController-投诉证据拖上传管理")
public class FileUploadController {
    @Resource
    private FileStorageServiceImpl fileStorageService;
    @ApiOperation("上传banner")
    @PostMapping("/upload1")
    public ResponseResult upload(@RequestParam("file") MultipartFile multipartFile) throws IOException, ServerException, InvalidBucketNameException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        if (multipartFile==null||multipartFile.getSize()==0){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        UUID uuid = UUID.randomUUID();
        String fileName=uuid+".html";
        String path = fileStorageService.uploadImageFile(fileName, multipartFile.getInputStream());
        return ResponseResult.okResult(path);
    }
}
